<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
// import resize from "./mixins/resize";
export default {
  // mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "240px",
    },
  },
  data() {
    return {
      chart: null,
      chartData: [
        { name: "新碶", value: 68 },
        { name: "北仑", value: 67 },
        { name: "大碶", value: 42 },
        { name: "霞浦", value: 18 },
        { name: "小港", value: 15 },
        { name: "春晓", value: 14 },
        { name: "大榭", value: 8 },
        { name: "戚家山", value: 8 },
        { name: "柴桥", value: 4 },
        { name: "鄞州区", value: 3 },
        { name: "梅山", value: 2 },
        { name: "高新区", value: 1 },
        { name: "东钱", value: 1 },
        { name: "郭巨", value: 1 },
      ],
    };
  },
  // created() {
  //   this.initChart();
  // },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      const that = this;
      this.chart.setOption({
        title: {
          text: "企业套餐会员分析",
          left: "",
          textStyle: {
            color: "#333",
            fontWeight: "bold",
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        xAxis: {
          type: "category",
          data: this.chartData.map((item) => item.name),
          axisLabel: {
            interval: 0,
            rotate: 45,
          },
        },
        yAxis: {
          type: "value",
          max: 70,
        },
        series: [
          {
            type: "bar",
            data: this.chartData.map((item) => item.value),
            itemStyle: {
              color: function (params) {
                const colorList = [
                  "#5470c6",
                  "#ee6666",
                  "#91cc75",
                  "#fac858",
                  "#73c0de",
                  "#9a60b4",
                  "#ff9896",
                  "#3ba272",
                  "#fc8452",
                  "#26c0c0",
                  "#ea7ccc",
                  "#a0a7e6",
                  "#c23531",
                  "#2f4554",
                ];
                return colorList[params.dataIndex % colorList.length];
              },
            },
          },
        ],
      });
    },
  },
};
</script>

<style scoped></style>
